
// pages/user/alter/alter.js
const urls = require('../../../utils/url.js').urls;
const http = require('../../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    types: 0,
    name: '',
    title: ''
  },
  fromSubmit: function(event) {
    var types = this.data.types;
    var name = event.detail.value.name;
    var zdm = '';

    if (types == 0) {
      //  姓名跳转
      zdm = "realname"
    } else if (types == 1) {
      //  座机跳转
      zdm = "zjh"
    } else if (types == 2) {
      //  手机跳转
      zdm = "phone"
    } else if (types == 3) {
      //  房间跳转
      zdm = "room"
    }
    var param = {
      openid: app.globalData.openid, //openid
      zdm: zdm, //字段名
      zdz: name //字段值
    };
    http(urls.getUserUpdate, param, function(res) {
      console.log(res)
      if (res.code == 0) {
        wx.navigateBack({
        })
        wx.showToast({
          title: res.msg,
        })
      }
    })


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      types: wx.getStorageSync("user_type"),
      name: wx.getStorageSync("user_name")
    })

    if (that.data.types == 0) {
      that.setData({
        title: '姓名:'
      })
      //  姓名跳转
    } else if (that.data.types == 1) {
      that.setData({
        title: '座机:'
      })
      //  座机跳转
    } else if (that.data.types == 2) {
      that.setData({
        title: '手机:'
      })
      //  手机跳转
    } else if (that.data.types == 3) {
      that.setData({
        title: '房间:'
      })
      //  房间跳转
    }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})